package com.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.MajorChange;
import com.hr.mapper.MajorChangeMapper;
import com.hr.service.MajorChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MajorChangeServiceImpl implements MajorChangeService {

        @Autowired
        private MajorChangeMapper majorChangeMapper;

        /**
         * 保存/修改
         * @param majorChange
         * @return
         */
        @Override
        public boolean save(MajorChange majorChange) {
            int row=0;
            if(majorChange.getMchid()==null){
                row = majorChangeMapper.insert(majorChange);
            }else{
                row = majorChangeMapper.updateById(majorChange);
            }

            return row >0;
        }

        /**
         * 分页查询
         * @param page
         * @return
         */
        @Override
        public Page<MajorChange> queryList(Page<MajorChange> page) {
            page=majorChangeMapper.queryList(page);
            return page;
        }

        /**
         * 单值查询
         * @param mchid
         * @return
         */
        @Override
        public MajorChange queryById(Integer mchid) {
            MajorChange majorChange = majorChangeMapper.selectById(mchid);
            return majorChange;
        }

        /**
         * 条件查询
         * @param majorChange
         * @return
         */
        @Override
        public List<MajorChange> queryListByReason(MajorChange majorChange) {
            QueryWrapper<MajorChange> queryWrapper = new QueryWrapper<MajorChange>();
            if(majorChange.getFirstKindId()!=null && !majorChange.getFirstKindId().isEmpty()){
                queryWrapper.eq("first_kind_id",majorChange.getFirstKindId());
            }
            if(majorChange.getSecondKindId()!=null && !majorChange.getSecondKindId().isEmpty()){
                queryWrapper.eq("second_kind_id",majorChange.getSecondKindId());
            }
            if(majorChange.getThirdKindId()!=null && !majorChange.getThirdKindId().isEmpty()){
                queryWrapper.eq("third_kind_id",majorChange.getThirdKindId());
            }
            if(majorChange.getNewMajorId()!=null && !majorChange.getNewMajorId().isEmpty()){
                queryWrapper.eq("major_id",majorChange.getMajorId());
            }
            if(majorChange.getNewMajorKindId()!=null && !majorChange.getNewMajorKindId().isEmpty()){
                queryWrapper.eq("major_kind_id",majorChange.getMajorKindId());
            }
            if(majorChange.getRegistTime() !=null){
                queryWrapper.between("regist_time","1990-01-01", new Date());
            }
            queryWrapper.eq("check_status",1);
            List<MajorChange> list = majorChangeMapper.selectList(queryWrapper);
            return list;
        }

}
